<?php
class ControllerReportService extends Controller
{
	private $error = array();
	
	public function debt()
	{
		$this->load->model("report/service");
		
		$usergroup = $this->request->get['type'];
		
		if($usergroup == 'employee')
		{
			$usergroup = "";
		}
		
		$this->data['reports'] = $this->model_report_service->debtlist(" AND `partner`.usergroup = '".$usergroup."'");
		$this->id='content';
		
		if($this->request->post['display'] == "report")
		{
			$this->template="report/debt_print.tpl";
		}
		else
		{
			$this->template="report/debt.tpl";
		}
		
		$this->layout="layout/function";
		
		$this->render();
	}
	
	public function debtuser()
	{
		$this->load->model("report/service");
		
		$userid = $this->request->get['userid'];
		
		$users = $this->model_report_service->debtlist(" AND `partner`.userid = '".$userid."'");
		
		$this->data['user'] = $users[0];
		
		$this->load->model("voucher/voucher");
		$this->load->model("common/control");
		
		$this->data['accounttype'] = array();
		$vouchergroups_expense = array(
				0 => array("vouchergroupid" => "VEXSP", "vouchergroupname" => "Payments to suppliers for goods and services (Ex: Purchase Order)"),
				1 => array("vouchergroupid" => "VEXCR", "vouchergroupname" => "Payments to customers for goods and services (Ex: Return order)"),
				2 => array("vouchergroupid" => "VEXES", "vouchergroupname" => "Salary"),
				3 => array("vouchergroupid" => "VEXEA", "vouchergroupname" => "Amortization (loss of intangible asset value over time)"),
				4 => array("vouchergroupid" => "VEXEO", "vouchergroupname" => "Office Operating cost / Purchase Assets (Ex: Electronic, Water, Buy assets for company using)"),
				5 => array("vouchergroupid" => "VEXSL", "vouchergroupname" => "DEBT/LOANS of partners"),
				6 => array("vouchergroupid" => "VEXCL", "vouchergroupname" => "DEBT/LOANS of customers"),
				7 => array("vouchergroupid" => "VEXEL", "vouchergroupname" => "DEBT/LOANS of employee"),
				8 => array("vouchergroupid" => "VEXSR", "vouchergroupname" => "RENT ASSETS or others from partners"),
				9 => array("vouchergroupid" => "VEXEM", "vouchergroupname" => "Marketing cost, public relationship"),
				10 => array("vouchergroupid" => "VEXCT", "vouchergroupname" => "Return the deposit for customer when they receive products"),
				11 => array("vouchergroupid" => "VEXCC", "vouchergroupname" => "Change money to customer"),
				12 => array("vouchergroupid" => "VEXEA", "vouchergroupname" => "Capital")
			);
			
		$vouchergroups_income = array(
				0 => array("vouchergroupid" => "VINCS", "vouchergroupname" => "Receipts from the sale of goods or services (Ex: Sale Order, Sale services )"),
				1 => array("vouchergroupid" => "VINEI", "vouchergroupname" => "Receipts from internal company (employee)"),
				2 => array("vouchergroupid" => "VINSR", "vouchergroupname" => "Receipts from the returning products to supplier"),
				3 => array("vouchergroupid" => "VINSL", "vouchergroupname" => "DPBT/LOANS of Suppliers"),
				4 => array("vouchergroupid" => "VINCL", "vouchergroupname" => "DPBT/LOANS of Customer"),
				5 => array("vouchergroupid" => "VINEL", "vouchergroupname" => "DPBT/LOANS of Employee"),
				6 => array("vouchergroupid" => "VINCD", "vouchergroupname" => "Receipts from customer deposit order/products"),
				7 => array("vouchergroupid" => "VINCH", "vouchergroupname" => "Receipts from customer change products"),
				8 => array("vouchergroupid" => "VINCO", "vouchergroupname" => "Receipts from customer for other activities"),
				9 => array("vouchergroupid" => "VINSC", "vouchergroupname" => "Supplier change money"),
				10 => array("vouchergroupid" => "VINEA", "vouchergroupname" => "Capital")
			);
			
		foreach($vouchergroups_expense as $item)
		{
			$this->data['accounttype'][$item['vouchergroupid']] = $item['vouchergroupname']; 
		}
		
		foreach($vouchergroups_income as $item)
		{
			$this->data['accounttype'][$item['vouchergroupid']] = $item['vouchergroupname']; 
		}
		
		$this->data['reports'] = $this->model_voucher_voucher->search(" AND `voucher`.partnerid = '".$userid."' AND `voucher`.grandtotal <> `voucher`.paymentamount ");
		
		
		$this->id='content';
		
		if($this->request->post['display'] == "report")
		{
			$this->template="report/debt_user_print.tpl";
		}
		else
		{
			$this->template="report/debt_user.tpl";
		}
		
		$this->layout="layout/function";
		
		$this->render();
	}
	
}
?>